<template>
	<view>
		<!-- 搜索栏 -->
		<view class="search">
			<uni-search-bar class="search_bar" placeholder="品质保障,安心家装" @confirm="search" @cancel="cancel"
				cancel-text="取消">
				<uni-icons slot="searchIcon" size="16" type="search" />
			</uni-search-bar>
		</view>

		<!-- swiper -->
		<view class="swiper_content">
			<text>全部品类</text>
			<swiper next-margin="250rpx" @change="change">
				<swiper-item v-for="(item,index) in swiperItems" :key="item.index">
					<view class="swiper-item">
						<image :src="item.src" mode="aspectFill"></image>
						<text>{{item.text}}</text>
					</view>
				</swiper-item>
			</swiper>
		</view>

		<!-- 单品推荐 -->
		<view class="recommend">
			<text class="recommend_title">单品推荐</text>
			<view>
				<view class="recommend_content">
					<view class="recommend_item" v-for="(item,index) in showData" :key="item.index">
						<image :src="item.src" mode="widthFix"></image>
						<uni-icons @click="join($event)" slot="cartIcon" size="14" color="#fff" :type="item.type" />
					</view>
				</view>
			</view>
			<!-- <view v-show="current === 0">
				<view class="recommend_content">
					<view class="recommend_item" v-for="(item,index) in recommendItems" :key="item.index">
						<image :src="item.src" mode="widthFix"></image>
						<uni-icons slot="cartIcon" size="14" color="#fff" type="cart" />
					</view>
				</view>
			</view>
			<view v-show="current === 1">
				<view class="recommend_content">
					<view class="recommend_item" v-for="(item,index) in sofaItems" :key="item.index">
						<image :src="item.src" mode="widthFix"></image>
						<uni-icons slot="cartIcon" size="14" color="#fff" type="cart" />
					</view>
				</view>
			</view>
			<view v-show="current === 2">
				<view class="recommend_content">
					<view class="recommend_item" v-for="(item,index) in tablewareItem" :key="item.index">
						<image :src="item.src" mode="widthFix"></image>
						<uni-icons slot="cartIcon" size="14" color="#fff" type="cart" />
					</view>
				</view>
			</view>
			<view v-show="current === 3">
				<view class="recommend_content">
					<view class="recommend_item" v-for="(item,index) in lampItem" :key="item.index">
						<image :src="item.src" mode="widthFix"></image>
						<uni-icons slot="cartIcon" size="14" color="#fff" type="cart" />
					</view>
				</view>
			</view>
			<view v-show="current === 4">
				<view class="recommend_content">
					<view class="recommend_item" v-for="(item,index) in bedItem" :key="item.index">
						<image :src="item.src" mode="widthFix"></image>
						<uni-icons slot="cartIcon" size="14" color="#fff" type="cart" />
					</view>
				</view>
			</view> -->
			<view class="remind">没有内容了</view>
		</view>
	</view>
</template>

<script>
	import categoryData from '../../static/js/categoryData.js'
	export default {
		data() {
			return {
				current: 0,
				// 显示数据
				showData:[],
				// 轮播图数据
				swiperItems: categoryData.data.swiperItems,
				// 柜架
				recommendItems: categoryData.data.recommendItems,
				// 沙发
				sofaItems: categoryData.data.sofaItems,
				//餐具厨具
				tablewareItem: categoryData.data.tablewareItem,
				// 灯具
				lampItem: categoryData.data.lampItem,
				// 床具
				bedItem: categoryData.data.bedItem,
			}
		},
		methods: {
			change(e) {
				this.current = e.target.current
				if(e.target.current === 0){
					this.showData = this.recommendItems
				}
				if(e.target.current === 1){
					this.showData = this.sofaItems
				}
				if(e.target.current === 2){
					this.showData = this.tablewareItem
				}
				if(e.target.current === 3){
					this.showData = this.lampItem
				}
				if(e.target.current === 4){
					this.showData = this.bedItem
				}
			},
			join(e){
				console.log(e);
			}
		},
		onLoad() {
			this.showData = this.recommendItems
		}
	}
</script>

<style lang="scss" scoped>
	.search {
		width: 750rpx;
		box-sizing: border-box;
	}

	// 全部分类
	.swiper_content {
		text {
			color: #000;
			font-size: 34rpx;
			padding: 30rpx 20rpx;
		}

		swiper {
			width: 750rpx;
			height: 500rpx;
			padding: 20rpx;
			box-sizing: border-box;

			swiper-item {
				height: 100%;
				padding-right: 50rpx;
				box-sizing: border-box;

				.swiper-item {
					height: 100%;
					position: relative;
					box-sizing: border-box;
					border-radius: 10rpx;
					overflow: hidden;

					image {
						width: 100%;
						height: 100%;
						display: block;
						border-radius: 10rpx;
					}

					text {
						padding: 10rpx 30rpx;
						font-size: 24rpx;
						border-radius: 50rpx;
						position: absolute;
						bottom: 30rpx;
						left: 50%;
						transform: translateX(-50%);
						color: #000;
						background: #fff;
					}
				}
			}
		}

	}

	// 单品推荐
	.recommend {
		.recommend_title {
			color: #000;
			font-size: 34rpx;
			padding: 30rpx 20rpx;
		}

		.recommend_content {
			padding: 20rpx 0;
			padding-right: 20rpx;
			display: flex;
			flex-wrap: wrap;

			.recommend_item {
				width: 50%;
				// padding: 20rpx 0;
				margin-bottom: 20rpx;
				padding-left: 20rpx;
				box-sizing: border-box;
				position: relative;

				image {
					width: 100%;
					height: 100%;
					display: block;
					border-radius: 10rpx;
				}

				uni-icons {
					width: 34rpx;
					height: 34rpx;
					line-height: 34rpx;
					text-align: center;
					padding: 10rpx;
					border-radius: 50rpx;
					position: absolute;
					bottom: 10rpx;
					right: 10rpx;
					background: $color;
				}
			}

		}

		.remind {
			padding: 0 0 20rpx 0;
			text-align: center;
			font-size: 24rpx;
			color: $color;
		}
	}
</style>
